import * as types from "../types/chooseDeviceModelTypes";

const initialState = {
  loading: false,
  initing: true,
  error: undefined,
  deviceModels: [],
  deviceList: [],
  curTag: 0,
  brandId: 1,
};

export default function chooseDeviceModelReducer(state = initialState, action) {
  switch (action.type) {
    case types.CHOOSEDEVICE_MAINLIST_INITING:
      return {
        ...state,
        initing: true,
      };
    case types.CHOOSEDEVICE_MAINLIST_DONE:
      return {
        ...state,
        deviceModels: action.deviceModels,
        brandId: action.brandId,
      };
    case types.CHOOSEDEVICE_MAINLIST_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.CHOOSEDEVICE_SUBLIST_INITING:
      return {
        ...state,
        loading: true,
      };
    case types.CHOOSEDEVICE_SUBLIST_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
        deviceList: action.deviceList,
      };
    case types.CHOOSEDEVICE_SUBLIST_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.CHOOSEDEVICE_TAGCHANGE:
      return {
        ...state,
        curTag: action.curTag,
      };
    case types.CHOOSEDEVICE_BRANDIDCHANGE:
      return {
        ...state,
        brandId: action.brandId,
      };
    case types.CHOOSEDEVICE_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
